<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 键盘事件对象中的keyCode属性可以得到相应键的ASCII码值
        // 1.keyup/keydown获取ASCII码时不区分字母大小写
        document.addEventListener('keyup', function (e) {
            console.log('up' + e.keyCode);
            // 我们可以利用keyCode的返回值ASCII码判断用户按下了那个键
            if (e.keyCode === 65) {
                alert('a键')
            } else {
                alert('no')
            }
        })
        // 2.keypress获取ASII码时区分字母大小写
        document.addEventListener('keypress', function (e) {
            console.log('press' + e.keyCode);
        })

    </script>
</body>

</html>